const root = {
    val: 14,
    left: {
        val: 7,
        left: {
            val: 3,
        },
        right: {
            val: 9,
        },
    },
    right: {
        val: 18,
        left: {
            val: 16,
        },
        right: {
            val: 19,
        },
    },
};

function TreeNode(val) {
    this.val = val
    this.left = null
    this.right = null
}

function insertIntoBST(root, val) {
    if (!root) {
        return new TreeNode(val)
    }
    if (val < root.val) {
        root.left = insertIntoBST(root.left, val)
    }
    if (val > root.val) {
        root.right = insertIntoBST(root.right, val)
    }
    return root
}

insertIntoBST(root, 9)
console.log(root);
module.exports = {
    TreeNode,
    insertIntoBST
}